package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao dao =new TeacherDao();
    //业务员的添加功能
    //创建一个库管对象，指挥库管对象将老师对象添加到数据
    public boolean addTeacher(Teacher tea) {
        return dao.addTeacher(tea);
    }

    //判断教师号是否存在
    public boolean isExists(String id) {
        Teacher[] teas =dao.findAllTeacher();
        boolean flag =false;
        for (int i = 0; i <teas.length ; i++) {
            if(teas[i] !=null&&teas[i].getId().equals(id)){
                flag =true;
                break;
            }
        }
        return flag;
    }

    //查询所有老师
    public Teacher[] findAllTeacher() {
        Teacher[] teas =dao.findAllTeacher();
        boolean flag =false;
        for (int i = 0; i <teas.length ; i++) {
            if(teas[i]!=null){
                flag=true;
            }
        }
        if(flag){
            return teas;
        }else {
            return  null;
        }
    }

    //删除老师
    public void deleteTeacher(String delId) {
        dao.deleteTeacher(delId);
    }

    //修改老师
    public void updateTeacher(String updateId, Teacher newTea) {
        dao.updateTeacher(updateId,newTea);
    }


}
